package com.xiao.springcloud.controller;

import com.xiao.springcloud.entity.Payment;
import com.xiao.springcloud.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/consumer/order")
public class OrderController {
    public static final String URL = "http://CLOUD-PROVIDER-PAYMENT";
    @Autowired
    public RestTemplate restTemplate;

    /**
     * 创建订单
     * @param payment
     * @return
     */
    @GetMapping(value="/create")
    public Result<Payment> create(Payment payment){
        return  restTemplate.postForObject(URL+"/payment/create", payment, Result.class);
    }

    /**
     *
     * @return
     */
    @GetMapping("/get/{id}")
    public Result<Payment> getPayment(@PathVariable("id") Long id){
        return restTemplate.getForObject(URL+"/payment/get/"+id, Result.class);
    }
}
